#include <reg52.h>
#include "key.h"

code uint8 number[]={0xc0,0xf9,0xa4,0xb0,0x99,
					 0x92,0x82,0xf8,0x80,0x90,
					 0xFF
				};
int8 n=0;
uint8 delay();

void init_timer0()
{
	TMOD|=0x01;
	TMOD&=0xFD;
	TR0=1;
	TH0=0XFC;
	TL0=0X66;
}
void init_int()
{
	EA=1;
	ET0=1;
}
void main()
{
	KeyOut1=0;
	P0=number[0];
	ENLED=0;ADDR3=1;
	ADDR0=0;ADDR1=0;ADDR2=0;
	init_timer0();
	init_int();
	while(1);
}

void interrupt_init() interrupt 0
{
	TR0=1;
	TH0=0XFC;
	TL0=0X66;
	if(!KeyInt1)
		{
			if(!KeyInt1&&delay())
			{
				if(9==n){
					n=0;
				}else{
					n++;
				}
				P0=number[n];
				while(!KeyInt1);
			}
		}
		if(!KeyInt2)
		{
			if(!KeyInt2&&delay()){
				if(0==n){
					n=0;
				}else{
					n--;
				}
				P0=number[n];
				while(!KeyInt2);
			}
		}
}

uint8 delay()
{
	static uint8 i=5;
	i--;
	if(i==0)
	{
		i=5;
		return 1;
	}else
	{
		return 0;
	}
}
